home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / SPECTRAL.TST / PUTXINT.CX < prev    next >
Text File  |  1995-08-03  |  2KB  |  67 lines

  1. /* ============ */
  2. /* PutXInt.cx    */
  3. /* ============ */
  4. #include <stdio.h>
  5. #include <xtendefs.h>
  6. #include <string.h>
  7. /* ========================================================= */
  8. /* fPutXInt - Prints integer part of extended value on Unit */
  9. /* ========================================================= */
  10. void
  11. fPutXInt(FILE *Unit, USHORT *XVal, short MinFld)
  12. {
  13.     char    AscVal[128] = {0};
  14.     USHORT  RndVal[NE];
  15.     short   CharCt = 2, ExpVal;
  16.     char   *CharLoc;
  17.  
  18.     XROUND(XVal, RndVal);
  19.     XTOASC(RndVal, AscVal, NDEC);
  20.  
  21.     CharLoc = strrchr(AscVal, 'E');
  22.     *CharLoc = '\0';
  23.  
  24.     sscanf(CharLoc + 1, "%d", &ExpVal);
  25.  
  26.     if (ExpVal < 0)
  27.     {
  28.     fprintf(Unit, " 0");        /* Minimum is two chars */
  29.     }
  30.     else
  31.     {
  32.     CharLoc = AscVal;
  33.     fprintf(Unit, "%c", *CharLoc++);/* First char is sign */
  34.     fprintf(Unit, "%c", *CharLoc++);/* Second char is digit */
  35.  
  36.     ++CharLoc;            /* Third char is '.' */
  37.  
  38.     for (; ExpVal; --ExpVal)
  39.     {
  40.         if (*CharLoc)        /* Print next character */
  41.         {
  42.         fprintf(Unit, "%c", *CharLoc++);
  43.         }
  44.         else
  45.         {
  46.         fprintf(Unit, "0");    /* Pad with zeros on right */
  47.         }
  48.         ++CharCt;
  49.     }
  50.     }
  51.     /* ------------------------------------- */
  52.     /* Fill Trailing Field Width with Blanks */
  53.     /* ------------------------------------- */
  54.     for (; CharCt < MinFld; ++CharCt)
  55.     {
  56.     fprintf(Unit, " ");
  57.     }
  58. }
  59. /* ========================================================= */
  60. /* PutXInt - Prints integer part of extended value on stdout */
  61. /* ========================================================= */
  62. void
  63. PutXInt(USHORT *XVal, short MinFld)
  64. {
  65.     fPutXInt(stdout, XVal, MinFld);
  66. }
  67.